function [s_Yresults, s_Ystats, s_Xresults] = ...
         TimeSerieTideAnalysis(signal, time, startdate, dt, lat, snr_crit)
%function [s_Yresults, s_Ystats, s_Xresults] = ...
%         TimeSerieTideAnalysis(signal, time, startdate, dt)
%
%s_Yresults = struct( ...
%        'signal', signal ...
%    ,   'residual', residual ...
%    ,   'tidepred', tidepred ...
%    ,   'amplitude', tidecon(:,1) ...
%    ,   'phase', tidecon(:,3) ...
%);
%
%s_Ystats = struct( ...
%        'snr', tidecon(:,1) ./ tidecon(:,2) ...
%    ,   'snr_crit', snr_crit ...
%    ,   'amperror', tidecon(:,2) ...
%    ,   'phaserror', tidecon(:,4) ...
%);
%
%s_Xresults = struct( ...
%        'freqname', freqname ...
%    ,   'freq', freq ...
%    ,   'time', time ...
%    ,   'startdate', startdate ...
%    ,   'dt', dt ...
%);

outfile = 'TSTA_out.txt'

[freqname, freq , tidecon, tidepred] =  ...
    T_TIDE( ...
        signal ...
        , 'interval', dt/3600. ...
        , 'start time', startdate ...
        , 'latitude', lat ...
        , 'output', outfile...
        , 'synthesis', snr_crit...
);
 
s_Yresults = struct( ...
        'signal', signal ...
    ,   'residual', signal - tidepred ...
    ,   'tidepred', tidepred ...
    ,   'amplitude', tidecon(:,1) ...
    ,   'phase', tidecon(:,3) ...
);

s_Ystats = struct( ...
        'snr', tidecon(:,1) ./ tidecon(:,2) ...
    ,   'snr_crit', snr_crit ...
    ,   'amperror', tidecon(:,2) ...
    ,   'phaserror', tidecon(:,4) ...
);

s_Xresults = struct( ...
        'freqname', freqname ...
    ,   'freq', freq ...
    ,   'time', time ...
    ,   'startdate', startdate ...
    ,   'dt', dt ...
);